{
LANG : PASCAL
PROB : pprime
}

program PPRIME;
const
  fi = 'pprime.in';
  fo = 'pprime.out';
  max = 10000;
var
  a, b : longint;
  p : array[1..max] of longint;
  l : longint;

procedure inp;
begin
  read(a, b);
end;

function prime(k : longint) : boolean;
var
  i, c : longint;
begin
  prime := false;
  c := trunc(sqrt(k));
  for i := 1 to l do
  begin
    if p[i] > c then break;
    if k mod p[i] = 0 then exit;
  end;
  prime := true;
end;

procedure init;
var
  i : longint;
begin
  l := 0;
  for i := 2 to 10000 do
    if prime(i) then
    begin
      inc(l);
      p[l] := i;
    end;
end;

procedure check(k : longint);
begin
  if (a <= k) and (k <= b) and prime(k) then writeln(k);
end;

procedure process;
var
  i1, i2, i3, i4, k : longint;
begin
  for i1 := 2 to 9 do check(i1);

  for i1 := 1 to 9 do
  begin
    k := 10*i1 + i1;
    check(k);
  end;

  for i1 := 1 to 9 do
    for i2 := 0 to 9 do
    begin
      k := 100*i1 + 10*i2 + i1;
      check(k);
    end;

  for i1 := 1 to 9 do
    for i2 := 0 to 9 do
    begin
      k := 1000*i1 + 100*i2 + 10*i2 + i1;
      check(k);
    end;

  for i1 := 1 to 9 do
    for i2 := 0 to 9 do
      for i3 := 0 to 9 do
      begin
        k := 10000*i1 + 1000*i2 + 100*i3 + 10*i2 + i1;
        check(k);
      end;

  for i1 := 1 to 9 do
    for i2 := 0 to 9 do
      for i3 := 0 to 9 do
      begin
        k := 100000*i1 + 10000*i2 + 1000*i3 + 100*i3 + 10*i2 + i1;
        check(k);
      end;

  for i1 := 1 to 9 do
    for i2 := 0 to 9 do
      for i3 := 0 to 9 do
        for i4 := 0 to 9 do
        begin
          k := 1000000*i1 + 100000*i2 + 10000*i3 + 1000*i4 + 100*i3 + 10*i2 + i1;
          check(k);
        end;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  init;
  inp;
  process;
  close(output);
  close(input);
end.